library(RMySQL)
m<-dbDriver("MySQL");
con<-dbConnect(m, user="writeuser", password="writeuser", host="localhost", dbname="flight");

res<-dbSendQuery(con, paste("select", 
"flight_history_id, minute(time(actual_runway_arrival))+ 60*hour(time(actual_runway_arrival))+24*60*(day(date(actual_runway_arrival)-13)) runway_arrival,",
"minute(time(actual_gate_arrival))+ 60*hour(time(actual_gate_arrival))+24*60*(day(date(actual_gate_arrival)-13)) gate_arrival, ",
"scheduled_air_time, ",
"minute(time(scheduled_runway_arrival))+ 60*hour(time(scheduled_runway_arrival))+24*60*(day(date(scheduled_runway_arrival)-13)) scheduled_arrival,",
"actual_runway_departure='MISSING' missing_departure,",
"minute(time(actual_runway_departure))+ 60*hour(time(actual_runway_departure))+24*60*(day(date(actual_runway_departure)-13)) actual_departure",
"from flighthistory ",
"where date(actual_runway_departure)<='2012-11-13' and actual_runway_arrival>'2012-11-13 14:24:00+00' ",
"and actual_runway_arrival!='MISSING' and actual_gate_arrival!='MISSING' limit 100;"));

data<-fetch(res, n=-1);

names(data);

#y<-(data['scheduled_arrival']-data['runway_arrival'])

attach(data)
#plot(scheduled_arrival, gate_arrival)

data$runway_delay<-data$runway_arrival-data$scheduled_arrival

#plot(runway_delay~scheduled_air_time)
#linr=lm(runway_delay~scheduled_air_time)
#abline(linr)

plot(runway_delay, actual_departure+scheduled_air_time-scheduled_arrival)
runway_lm<-lm(runway_arrival~actual_departure+scheduled_air_time)










